import java.util.LinkedList;
import java.util.ListIterator;

public class Test {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);
        System.out.println(list.toString());
        for(Integer x:list) {
            System.out.print(x+" ");
        }
        System.out.println();

        ListIterator<Integer> it = list.listIterator();
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();

        ListIterator<Integer> it2 = list.listIterator(list.size());
        while(it2.hasPrevious()){
            System.out.print(it2.previous()+ " ");
        }
        System.out.println();
    }
}
